from src.main.dao.BaseDao import BaseDao

class ModuleDao(BaseDao):
    def insert_module(self, parent_module_id, module_name, module_icon=None, module_url=None, display_order=None):
        query = "INSERT INTO bk_module (parent_module_id, module_name, module_icon, module_url, display_order) VALUES (%s, %s, %s, %s, %s)"
        values = (parent_module_id, module_name, module_icon, module_url, display_order)
        return self.execute_sql(query, values)

    def update_module(self, module_id, parent_module_id, module_name, module_icon=None, module_url=None, display_order=None):
        query = "UPDATE bk_module SET parent_module_id = %s, module_name = %s, module_icon = %s, module_url = %s, display_order = %s WHERE module_id = %s"
        values = (parent_module_id, module_name, module_icon, module_url, display_order, module_id)
        return self.execute_sql(query, values)

    def delete_module(self, module_id):
        query = "DELETE FROM bk_module WHERE module_id = %s"
        values = (module_id,)
        return self.execute_sql(query, values)

    def get_all_modules(self):
        query = "SELECT * FROM bk_module"
        return self.execute_query(query)

    def get_module_by_id(self, module_id):
        query = "SELECT * FROM bk_module WHERE module_id = %s"
        values = (module_id,)
        return self.execute_query(query, values)

    def get_modules_by_parent_id(self, parent_module_id):
        query = "SELECT * FROM bk_module WHERE parent_module_id = %s"
        values = (parent_module_id,)
        return self.execute_query(query, values)
